#include"common.hpp"

extern Log log;

int main()
{
    int shmid=CreateShm();  //创建共享内存
    log(Debug,"create shm done");
    sleep(5);

    char *shmaddr=(char*)shmat(shmid,nullptr,0);  //关联共享内存
    log(Debug,"attach shm done,shmaddr: 0x%x",shmaddr);
    sleep(5);

    //进程通信
    while(true)
    { 
        cout<<"processb say@ "<<shmaddr<<endl;   //直接访问共享内存（这里shmaddr可以直接看作虚拟地址),不需要调用系统调用
        sleep(1);
    }

    shmdt(shmaddr);     //去关联
    log(Debug,"detach shm done,shmaddr: 0x%x",shmaddr);
    sleep(5);

    shmctl(shmid,IPC_RMID,nullptr);  //删除共享内存
    log(Debug,"destroy shm done,shmaddr: 0x%x",shmaddr);
    sleep(5);

    return 0;
}